import { createRouter, createWebHistory } from "vue-router";
import HomeView from "../views/HomeView.vue";

const routes = [
  {
    path: "/",
    name: "home",
    component: HomeView,
    meta: {
      title: "首页",
    },
  },
  // {
  //   path: '/admin',
  //   name: 'home',
  //   component: HomeView
  // },
  {
    path: "/pindao.html",
    name: "pindao",
    component: () => import("../views/Pindao.vue"),
    meta: {
      title: "频道列表",
    },
  },
  {
    path: "/audiolist.html",
    name: "audioList",
    component: () => import("../views/AudioList.vue"),
    meta: {
      title: "播放列表",
    },
  },
  {
    path: "/search.html",
    name: "search",
    component: () => import("../views/Search.vue"),
    meta: {
      title: "查询列表",
    },
  },
];

// 百度统计代码
function baiduTrackPageview(to) {
  try {
    const label = "芒果团活动-" + to.meta.title || "";
    if (window._hmt)
      console.log(window._hmt, window.location.origin + "---" + label);
    window._hmt.push([
      "_trackPageview",
      window.location.origin + "---" + label,
    ]);
  } catch (err) {
    console.log("百度统计问题");
  }
}
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});
router.beforeEach((to, from, next) => {
  baiduTrackPageview(to);
  const isPindao = true;
  if (isPindao || to.name === "home") {
    next();
  } else {
    next({ name: "home" });
  }
});
export default router;
